<template>
  <!-- 招标需求业务请示 -->
    <CommonTitle titleName="招标需求业务请示"></CommonTitle>
    <div class="box">
        <el-form
                :inline="true"
                label-width="140"
                :model="formInline"
                :rules="rules"
                ref="formRef"
                class="demo-form-inline"
        >
            <el-row>
                <el-col :span="8" v-if="state.disabled">
                    <el-form-item label="审核编号">
                        <el-input v-model="formInline.flowId" disabled placeholder="" />
                    </el-form-item>
                </el-col>
                <el-col :span="8" v-if="state.disabled">
                    <el-form-item label="审核状态">
                        <el-select v-model="formInline.examineStatus" disabled>
                            <el-option
                                    v-for="item in state.auditStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8" v-if="state.disabled">
                    <el-form-item label=" ">
                        <el-button
                                type="primary"
                                @click="
                () => {
                  window.open(state.formInline.routeUrl)
                }
              "
                        >查看流程审批</el-button
                        >
                    </el-form-item>
                </el-col>
                <el-col :span="8"
                ><el-form-item label="所属部门">
                    <el-input
                            v-model="formInline.departmentName"
                            disabled
                            placeholder=""
                    />
                </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="所属项目集">
                        <el-input
                                v-model="formInline.projectSetName"
                                disabled
                                placeholder=""
                        />

                        <!-- <el-select
                          v-model="formInline.projectSetName"
                          disabled
                          placeholder="Activity zone"
                        >
                          <el-option label="Zone one" value="shanghai" />
                          <el-option label="Zone two" value="beijing" />
                        </el-select> -->
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目集编号">
                        <el-input
                                v-model="formInline.projectSetId"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目负责人">
                        <el-input
                                v-model="formInline.responsibleUserName"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="所属项目">
                        <el-input
                                v-model="formInline.projectName"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目编号">
                        <el-input
                                v-model="formInline.projectId"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="业务描述">
                        <el-input
                                v-model="formInline.problemNature"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="所属阶段">
                        <el-input
                                v-model="formInline.projectStage"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="项目类型">
                        <el-input
                                v-model="formInline.projectType"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="所属任务">
                        <el-input
                                v-model="formInline.projectTask"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="任务代码">
                        <el-input
                                v-model="formInline.projectTaskCode"
                                disabled
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="业务标题" prop="requestTitle">
                        <el-input
                                :disabled="state.disabled"
                                v-model="formInline.requestTitle"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="紧急程度" prop="urgentDegree">
                        <el-select
                                :disabled="state.disabled"
                                v-model="formInline.urgentDegree"
                                placeholder=""
                        >
                            <el-option
                                    v-for="item in urgencyList"
                                    :key="item"
                                    :label="item.label"
                                    :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <!--                <el-col :span="8">
                    <el-form-item label="预算控制价" prop="budgetControlPrice">
                        <el-input
                            :disabled="state.disabled"
                            v-model="formInline.budgetControlPrice"
                            placeholder="请输入预算控制价"
                        />
                    </el-form-item>
                </el-col>-->
                <el-col :span="8">
                    <el-form-item label="预估金额" prop="estimateMoney">
                        <el-input
                                :disabled="state.disabled"
                                v-model="formInline.estimateMoney"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="业务类别" prop="businessType">
                        <el-select
                                :disabled="state.disabled"
                                v-model="formInline.businessType"
                                placeholder=""
                        >
                            <el-option
                                    v-for="item in businessTypeList"
                                    :key="item"
                                    :label="item.label"
                                    :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="8">

                   <el-form-item label="服务范围" prop="startCheckTime">
                    <el-date-picker
                      v-model="formInline.startCheckTime"
                      :disabled="state.disabled"
                      type="daterange"
                      range-separator="-"
                      start-placeholder="开始时间"
                      end-placeholder="结束时间"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      :size="size"
                    />
                  </el-form-item>
                </el-col> -->

                <!--                <el-col :span="8">
                    <el-form-item label="业务类型" prop="requestType">
                        <el-select
                                :disabled="state.disabled"
                                v-model="formInline.requestType"
                                placeholder=""
                        >
                            <el-option
                                    v-for="item in projectList"
                                    :key="item"
                                    :label="item.label"
                                    :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>-->
                <el-col :span="8">
                    <el-form-item label="招标方式" prop="projectTendersWay">
                        <el-select
                                :disabled="state.disabled"
                                v-model="formInline.projectTendersWay"
                                placeholder=""
                        >
                            <el-option
                                    v-for="item in state.projectTendersWayList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <!--                <el-col :span="8">
                    <el-form-item label="招标类别" prop="biddingCategory">
                        <el-select
                            v-model="formInline.biddingCategory"
                            value-key=""
                            :disabled="state.disabled"
                            placeholder="招标类别"
                            clearable
                        >
                            <el-option
                                v-for="item in categoryOfTenderList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>-->
                <el-col :span="8">
                    <el-form-item label="服务范围" prop="startCheckTime">
                        <el-date-picker
                            :disabled="state.disabled"
                            v-model="formInline.checkTimeValue"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            @change="checkTimeChange"
                            type="datetimerange"
                            range-separator="-"
                            start-placeholder="服务范围开始"
                            end-placeholder="服务范围结束"
                            size="large"
                        />
                    </el-form-item>
                </el-col>
<!--                <el-col :span="8">
                    <el-form-item label="资金来源" prop="fundSource">
                        <el-input
                            :disabled="state.disabled"
                            v-model="formInline.fundSource"
                            placeholder=""
                        />
                    </el-form-item>
                </el-col>-->
                <el-col :span="24">
                    <el-form-item label="会审部门" prop="reviewDepartment">
                        <el-select
                                v-model="formInline.reviewDepartment"
                                value-key=""
                                :disabled="state.disabled"
                                placeholder="会审部门"
                                clearable
                                multiple
                                filterable
                        >
                            <el-option
                                    v-for="item in state.departmentOptions"
                                    :key="item.departmentId"
                                    :label="item.departmentName"
                                    :value="item.departmentId"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="业务简述" prop="projectBiddingExplain">
                        <el-input
                                :disabled="state.disabled"
                                v-model="formInline.projectBiddingExplain"
                                type="textarea"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>

                <el-col :span="24">
                    <el-form-item label="相关附件" prop="files">
                        <FileMinioUpload
                                :disabled="state.disabled"
                                :restriction="true"
                                :restrictionLimit="9"
                                @updateFiles="updateFiles"
                                v-model:files="formInline.files"
                                :show-button="!state.disabled"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="24" >
                    <CommonTitle titleName="其他信息"></CommonTitle>
                </el-col>
                <el-col :span="8" >
                    <el-form-item label="申请人">
                        <el-input disabled v-model="formInline.createName" placeholder="" />
                    </el-form-item>
                </el-col>

                <el-col :span="8" >
                    <el-form-item label="申请部门">
                        <el-input
                                disabled
                                v-model="formInline.createDepartmentName"
                                placeholder=""
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="8" >
                    <el-form-item label="创建时间">
                        <el-input disabled v-model="formInline.createTime" placeholder="" />
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="isLook!=1" >
                    <el-button @click="submit" type="primary" class="button_view">发起审批</el-button>
                    <el-button type="primary" @click="goback" class="button_cancel2"> 取消 </el-button>
                  </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script setup>
import { businessApi, department } from '@/api/project'
import { ref, reactive, onBeforeMount, onMounted } from 'vue'
import {
    ElDialog,
    ElForm,
    ElDatePicker,
    ElFormItem,
    ElRow,
    ElCol,
    ElMessage,
} from 'element-plus'
import CommonTitle from '@/components/CommonTitle.vue'
import FileMinioUpload from "@/components/FileMinioUpload.vue";
import { useRouter, useRoute } from 'vue-router'
import {taskApi} from "@/api/investment";

let router = useRouter()
let route = useRoute()

const getProjectId = router.currentRoute.value.params.projectId;
const getProjectTaskId = router.currentRoute.value.params.projectTaskId;
const getItemId = router.currentRoute.value.params.itemId;
const isLook = router.currentRoute.value.params.isLook;

const formInline = reactive({
    files: [],
    requestType:'',
    projectTendersWay:'',
    meetingName: '',
    approvalOpinion: '',
    checkTimeValue:[]
})
// 1:待审核 2:审核成功 3:审核驳回
const state = reactive({
    auditStatus: [
        {
            label: '待审核',
            value: '1'
        },
        {
            label: '审核成功',
            value: '2'
        },
        {
            label: '审核驳回',
            value: '3'
        }
    ],
// "1公开招标",
// "2公开竞争性谈判",
// "3公开竞争性磋商",
// "4择优比选",
// "5单一来源采购（公开）"
// "6邀请竞争性谈判", "
// "7邀请竞争性磋商", "
// "8择优询价",
// "9单一来源采购（非公开）
    projectTendersWayList:[
        {
            label: '公开招标',
            value: '1'
        },
        {
            label: '公开竞争性谈判',
            value: '2'
        },
        {
            label: '公开竞争性磋商',
            value: '3'
        },
        {
            label: '择优比选',
            value: '4'
        },
        {
            label: '单一来源采购（公开）',
            value: '5'
        },
        {
            label: '邀请竞争性谈判',
            value: '6'
        },
        {
            label: '邀请竞争性磋商',
            value: '7'
        },
        {
            label: '择优询价',
            value: '8'
        },
        {
            label: '单一来源采购（非公开）',
            value: '9'
        }
    ],

    projectTaskId: '',
    departmentOptions: [],
    disabled: false,
    projectId: '',
    itemId:'',
    user: ''
})

//固定值 676628435627033400=工程类-施工类 -5707408146184845961=工程类-货物采购类 7560208448710396929=工程类-勘察、设计、监理服务类 -3267680363755058876=工程类-检测、监测、咨询、测绘、图审等其他工程服务类 413998337239041580=非工程类-修缮改造类 4291094611656655124=非工程类-设施设备系统维保及维修类 -1203932655659367791=非工程类-物业服务类 6837816167438960732=非工程类-物资采购类 -6752169256032911253=非工程类-其他服务类
const categoryOfTenderList = reactive([
    {
        label: '工程类-施工类',
        value: '676628435627033400'
    },
    {
        label: '工程类-货物采购类',
        value: '-5707408146184845961'
    },
    {
        label: '工程类-勘察、设计、监理服务类',
        value: '7560208448710396929'
    },
    {
        label: '工程类-检测、监测、咨询、测绘、图审等其他工程服务类',
        value: '-3267680363755058876'
    },
    {
        label: '非工程类-修缮改造类',
        value: '413998337239041580'
    },
    {
        label: '非工程类-设施设备系统维保及维修类',
        value: '4291094611656655124'
    },
    {
        label: '非工程类-物业服务类',
        value: '-1203932655659367791'
    },
    {
        label: '非工程类-物资采购类',
        value: '6837816167438960732'
    },
    {
        label: '非工程类-其他服务类',
        value: '-6752169256032911253'
    }
])

const rules = {
    biddingCategory: [
        { required: true, message: '招标类别不能为空', trigger: 'change' }
    ],
    requestTitle: [
        { required: true, message: '业务标题不能为空', trigger: 'blur' }
    ],
    budgetControlPrice: [
        { required: true, message: '预算控制价不能为空', trigger: 'blur' }
    ],
    estimateMoney: [
        { required: true, message: '预估金额不能为空', trigger: 'blur' }
    ],
    urgentDegree: [
        { required: true, message: '紧急程度不能为空', trigger: 'blur' }
    ],

    startCheckTime: [
        { required: true, message: '服务范围不能为空', trigger: 'change' }
    ],
    requestType: [
        { required: true, message: '业务类型不能为空', trigger: 'blur' }
    ],
    projectTendersWay: [
        { required: true, message: '招标方式不能为空', trigger: 'blur' }
    ],
    businessType: [
        { required: true, message: '业务类别不能为空', trigger: 'blur' }
    ],
    reviewDepartment: [
        { required: true, message: '会审部门不能为空', trigger: 'blur' }
    ],
    projectBiddingExplain: [
        { required: true, message: '议题简述不能为空', trigger: 'blur' }
    ],
    projectPeriodExplain: [
        { required: true, message: '项目周期说明不能为空', trigger: 'blur' }
    ],
    projectControlExplain: [
        { required: true, message: '招标控制价说明不能为空', trigger: 'blur' }
    ],
    files: [{ required: true, message: '议题附件不能为空', trigger: 'blur' }]
}
const updateFiles = () => {}
const goback = () => {
    router.go(-1)
}
// (0:非业务的日常管理经费,1:咨询服务类,2:备用金借款,3:财务数据报出,4:其他及涉及业务的内容,5:养老内容)
const businessTypeList = reactive([
    {
        label: '非业务的日常管理经费',
        value: '12'
    },
    {
        label: '咨询服务类',
        value: '13'
    },
    {
        label: '备用金借款',
        value: '14'
    },
    {
        label: '财务数据报出',
        value: '15'
    },
    {
        label: '其他及涉及业务的内容',
        value: '16'
    },
    {
        label: '养老内容',
        value: '17'
    }
])
// 0:公开招标,1:择优比选,2:公开竞争性谈判,3:单一来源采购(公开),4:择优询价,5:邀请竞争性磋商,6:邀请竞争性谈判,7:单一 来源采购(非公开)
const biddingCategoryList = reactive([
    {
        label: '工程类-施工类',
        value: '0'
    },
    {
        label: '工程类-货物采购类',
        value: '1'
    },
    {
        label: '工程类-勘察、设计、监理服务类',
        value: '2'
    },
    {
        label: '非工程类-修缮改造类',
        value: '3'
    },
    {
        label: '非工程类-设施设备系统维保及维修类',
        value: '4'
    },
    {
        label: '非工程类-物业服务类',
        value: '5'
    },
    {
        label: '非工程类-物资采购类',
        value: '6'
    },
    {
        label: '非工程类-其他服务类',
        value: '7'
    }
])
//(0:普通,1:加急,2:平急,3:特急,4:特提)
const urgencyList = reactive([
    {
        label: '普通',
        value: '0'
    },
    {
        label: '加急',
        value: '1'
    },
    {
        label: '平急',
        value: '2'
    },
    {
        label: '特急',
        value: '3'
    },
    {
        label: '特提',
        value: '4'
    }
])
// (-5403873840876272513=招标项目 6597315479569055834=投资项目 960330435988177277=建设项目 -2375352083915127206 其他项目
const projectList=reactive([
    {
        label: '招标项目',
        value: '0'
    },
   /* {
        label: '投资项目',
        value: '1'
    },
    {
        label: '建设项目',
        value: '2'
    },
    {
        label: '其他项目',
        value: '3'
    }*/
])
//获取所有部门信息
const getdepartmentList = () => {
    department.getAllDepartments().then((res) => {
        state.departmentOptions = res?.data || []
    })
}
const formRef = ref(null)
const submit = () => {
    formRef.value.validate(async (valid, fields) => {
        if (valid) {
            if (formInline.files.length == 0) {
                ElMessage.error('请上传相关附件')
                return
            }
            formInline.projectId = state.projectId
            formInline.taskId = state.projectTaskId
            formInline.itemId = state.itemId
            let obj = JSON.parse(JSON.stringify(formInline))
            obj.startCheckTime = formInline.startCheckTime;
            obj.endCheckTime = formInline.endCheckTime;
            obj.fundSource = formInline.fundSource;


            obj.projectId = getProjectId;
            obj.taskId = getProjectTaskId;
            obj.itemId = getItemId;

            await taskApi.addProjectBusinessRequest(obj).then((res) => {
                if (res.code == '200') {
                    ElMessage.success('操作成功')
                    router.go(-1)
                }
            })
        }
    })
}

/**
 * 时间选择
 */
const checkTimeChange = (e) => {
  if(e && Array.isArray(e)){
      formInline.startCheckTime = e[0];
      formInline.endCheckTime = e[1];
  }
  if(!e){
      formInline.startCheckTime = '';
      formInline.endCheckTime = '';
  }
}

onMounted(() => {
    taskApi
        .getProjectBusinessRequest({ taskId: getProjectTaskId,itemId:getItemId, projectId: getProjectId })
        .then((res) => {
            if (res.code == '200') {
                for (const key in res.data) {
                    if (Object.hasOwnProperty.call(res.data, key)) {
                        if (key == 'startCheckTime') {
                            formInline.checkTimeValue = [res.data['startCheckTime'],res.data['endCheckTime']];
                            formInline['startCheckTime'] = res.data['startCheckTime'];
                            formInline['endCheckTime'] = res.data['endCheckTime'];
                            continue
                        }
                        if (key == 'files') {
                            formInline[key] = res.data[key] || []
                            continue
                        }
                        formInline[key] = res.data[key]
                    }
                }
            }
        })
    getdepartmentList()
})
</script>

<style lang="scss" scoped>
.el-form-item,
.el-select {
  width: 100%;
}
.box {
  border-radius: 10px;
  border: 1px solid #e3e7f1;
  padding: 34px 90px;
}
</style>
